let d = document;
let reg = d.querySelector(".reg_form");
let regBtn = reg.querySelector(".btn");
let isPC = IsPC();

bind(isPC, regBtn);

function bind(isPC, el) {
  if (!isPC) {
    el.addEventListener("touchend", theRegister);
    return
  }
  el.addEventListener("click", theRegister);
}

function theRegister() {
  let usr = reg.querySelector(".username");
  let pwd = reg.querySelector(".password");
  let dPwd = reg.querySelector(".affirm_password");
  let isT = false;
  if (usr.value.trim() != "") {
    isT = true
  } else {
    usr.classList.add("wamming")
  }
  if (pwd.value.trim() != "") {
    isT = true
  } else {
    pwd.classList.add("wamming")
  }
  if (dPwd != "" && dPwd.value.trim() == pwd.value.trim()) {
    isT = true
  } else {
    dPwd.classList.add("wamming")
  }
  if (isT) {
    let res = regStorage({
      username: usr.value.trim(),
      password: pwd.value.trim()
    });
    if (res === 4) {
      tooltip(d.body, {
        message: "注册成功"
      });
      sessionStorage.setItem("user_session", usr.value.trim());
      pwd.value = dPwd.value = usr.value = "";
      setTimeout(() => {
        window.location.href = "index.html"
      }, 2000)
    } else if (res === 5) {
      tooltip(d.body, {
        message: "注册失败，用户被注册"
      })
    }
  } else {
    tooltip(d.body, {
      message: "账号或密码有误"
    })
  }
}